//
//  ClientList.m
//  POS
//
//  Created by sigma xu on 20/4/13.
//  Copyright (c) 2013 sigma xu. All rights reserved.
//

#import "ClientListTVC.h"

@interface ClientListTVC ()

@end

@implementation ClientListTVC
@synthesize client_list;

#pragma mark -
#pragma mark View lifecycle
- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    ClientDBO *cdbo = [[ClientDBO alloc] init];
    client_list=cdbo.load_clients_list;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.client_list count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ClientListCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    // Configure the cell...
    if (cell == nil){
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:CellIdentifier];
    }
    if (indexPath.section == 0) {
        ClientDBO *cdbo = [self.client_list objectAtIndex:indexPath.row];
        cell.textLabel.text = cdbo.client_name;
    }
    return cell;
}
#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"sg_cl_cld"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        ClientDBO *cdbo = [self.client_list objectAtIndex:indexPath.row];
        ClientDetailTVC *cdtvc=(ClientDetailTVC *)[segue destinationViewController];
        cdtvc.id_client = cdbo.id_client;
        [cdtvc.tableView reloadData];
    }
}

@end
